class Solution {
public:
    vector<int> plusOne(vector<int> &digits) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int n = digits.size();
        vector<int> ans;
        int carry = 1;

        for (int i = n - 1; i >= 0 || carry; --i) {
            if (i >= 0) {
                carry += digits[i];
            }
            ans.push_back(carry % 10);
            carry /= 10;
        }
        reverse(ans.begin(), ans.end());
        return ans;
    }
};
